import { ImageResponse } from 'next/og'; import { api, safe } from '@/lib/api'; import { fmtDate, fmtInt } from '@/lib/format'; import { OBJECT_TYPE_LABELS, ORBIT_CLASS_COLORS, STATUS_COLORS } from '@/lib/site'; export const size = { width: 1200, height: 630 }; export const contentType = 'image/png'; export const alt = 'SatelliteIndex — satellite orbit card'; // OG renderer cannot resolve CSS variables: mirror the hex tokens from globals.css. const HEX: Record = { 'var(--active)': '#38d17f', 'var(--inactive)': '#7c869e', 'var(--ink-3)': '#6b7694', 'var(--warn)': '#f5a524', 'var(--danger)': '#ff5c6c', 'var(--accent-2)': '#8f7dff', 'var(--leo)': '#38d3ff', 'var(--meo)': '#8f7dff', 'var(--geo)': '#f5b544', 'var(--heo)': '#ff7ab6', 'var(--other)': '#7c869e', }; const hex = (v: string | undefined, fallback: string) => (v ? HEX[v] ?? fallback : fallback); export default async function Image({ params }: { params: Promise<{ slug: string }> }) { const { slug } = await params; const res = await safe(api.satellite(slug)); const d = res?.data ?? null; const statusColor = hex(STATUS_COLORS[d?.status ?? 'UNKNOWN'], '#7c869e'); const orbitColor = hex(ORBIT_CLASS_COLORS[d?.orbit_class ?? 'UNKNOWN'], '#7c869e'); const live = d?.live && d.live.error == null ? d.live : null; const alt = live ? `${fmtInt(live.altitude_km)} km` : d?.orbital_state ? `${fmtInt(d.orbital_state.perigee_km)}–${fmtInt(d.orbital_state.apogee_km)} km` : '—'; return new ImageResponse( (
SatelliteIndex
{d && (
{`NORAD ${d.norad_id ?? '—'}${d.cospar_id ? ` · ${d.cospar_id}` : ''}`}
)}
{d ? (
22 ? 64 : 88, fontWeight: 700, letterSpacing: -3, lineHeight: 1 }}>{d.name}
{d.status.charAt(0) + d.status.slice(1).toLowerCase()}
{OBJECT_TYPE_LABELS[d.object_type] ?? d.object_type}
{d.orbit_class &&
{d.orbit_class}
} {d.operator_name &&
{`· ${d.operator_name}`}
}
) : (
Object not catalogued
)}
{[ ['Altitude', alt], ['Inclination', d?.orbital_state ? `${d.orbital_state.inclination.toFixed(2)}°` : d?.inclination_deg != null ? `${Number(d.inclination_deg).toFixed(2)}°` : '—'], ['Period', d?.orbital_state?.period_minutes ? `${d.orbital_state.period_minutes.toFixed(1)} min` : '—'], ['Launched', fmtDate(d?.launch_date)], ].map(([k, v]) => (
{k}
{v}
))}
), { ...size }, ); }